package com.ruoyi.web.controller.doulai;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.PlayCount;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.service.IPlayCountService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.ExcelUtil;

/**
 * 游戏局数 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-01-06
 */
@Controller
@RequestMapping("/doulai/playCount")
public class PlayCountController extends BaseController
{
    private String prefix = "doulai/playCount";
	
	@Autowired
	private IPlayCountService playCountService;
	

	@GetMapping()
	public String playCount()
	{
	    return "/pages/statistics/statistics";
	}
	@GetMapping("/proxy")
	public String playCountProxy()
	{
		return "/pages/statistics/statistics2";
	}
	
	/**
	 * 综合统计
	 */
	@RequiresPermissions("doulai:playCount:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(int type,String date,int typePosition)
	{
		startPage();
		//1为日  2为月
        Map<String,Object> params = new HashMap<>();
		params.put("type",type);
		params.put("date",date);

		List<String> dates = new ArrayList<>();
		if(type == 1){
			dates.add(DateUtils.getDateAddDay(date,0));
			dates.add(DateUtils.getDateAddDay(date,-1));
			dates.add(DateUtils.getDateAddDay(date,-2));
			dates.add(DateUtils.getDateAddDay(date,-3));
			dates.add(DateUtils.getDateAddDay(date,-4));
			dates.add(DateUtils.getDateAddDay(date,-5));
			dates.add(DateUtils.getDateAddDay(date,-6));
		}
		if(type == 2){
			dates.add(DateUtils.getDateAddMonth(date,0));
			dates.add(DateUtils.getDateAddMonth(date,-1));
			dates.add(DateUtils.getDateAddMonth(date,-2));
			dates.add(DateUtils.getDateAddMonth(date,-3));
			dates.add(DateUtils.getDateAddMonth(date,-4));
			dates.add(DateUtils.getDateAddMonth(date,-5));
			dates.add(DateUtils.getDateAddMonth(date,-6));
		}

		//超级管理员
		if(typePosition == 1){
			List<Map<String,Object>> list = new ArrayList<>();
			for(String dateString:dates){
				params.put("date",dateString);
				Map<String,Object> map = playCountService.selectPlayCountList(params);
				if(type == 2){
					map.put("createTime",dateString.substring(0,7));
				}
				else {
					map.put("createTime",dateString);
				}
				list.add(map);
			}
			return getDataTable(list);
		}
		//代理
		else {
			List<Map<String,Object>> list = new ArrayList<>();
			Long gameUserId = super.getSysUser().getGameUserId();
			for(String dateString:dates){
				params.put("date",dateString);
				params.put("gameUserId",gameUserId);
				Map<String,Object> map = null;
				if(type == 2){
					map = playCountService.selectAgencyDataListMonth(params);
					map.put("createTime",dateString.substring(0,7));
				}
				else {
					map = playCountService.selectAgencyDataList(params);
					map.put("createTime",dateString);
				}
				list.add(map);
			}
			return getDataTable(list);
		}
	}
	

	

	
}
